<script>
import Common from "@/mixins/order/common.js";
import OrderService from "@/api/order/OrderService.js";
import PPMForm from "@/crm3.0part7-ppm/core/ppmForm.vue";
import pageShowDetail from "@/utils/pageShowDetail.js";

import { mapState } from "vuex";
export default {
  name: "demandConfirmPPM",
  mixins: [PPMForm, Common],
  data() {

        return {

        };
    },
  computed: {
    ...mapState("user", ["user", "busiManagerId", "custManagerId"]),
  },
  mounted() {
     this.formData["23868-100012377"].value = this.user.staffName;

     this.formData["23868-100012440"].value =  this.$util.dateFormat(new Date(),"yyyy-MM-dd hh-mm-ss")

      var custOrder = JSON.parse(localStorage.getItem("custOrder_select"));
      var cacheInfo = JSON.parse(localStorage.getItem("cacheInfo"));
             let temp = {
              custId: custOrder.custId,
              orderSource: "ORDER",
              custSoNumber: custOrder.custSoNumber,
              orderItemIds: cacheInfo.orderItemIds,
              taskId:cacheInfo.taskId
            };
            this.setPageOfferDetail(temp);

    },
    computed: {
      },
    methods: {
       async setPageOfferDetail(temp) {

      
      
      let res = await OrderService.qryPageOfferDetail(temp);
      
      if (res.resultCode == "0") {
          var ordProdInstAttrs = res.ORDER_DETAIL[0].ORD_PROD_INST_ATTR;
          var ordProdInsts = res.ORDER_DETAIL[0].ORD_PROD_INST;
          
           
          var ordProdInst2 = ordProdInstAttrs.filter(item =>{ return item.attrId == '142002621' && item.roleCd == '0'});
           
          var newValue = ordProdInst2[0].attrValue;
          
          var ordProdInst = ordProdInsts.filter(item =>{ return item.roleCd == 0});
                                                                   
          var oldValue = ordProdInst[0].handleOrgId;
          

          this.formData["23868-142002621"].value = newValue;
          this.formData["23868-100013695"].value = oldValue;


          var params = {
              interFaceType: "ORDER",
              sqlId:"2021072802",
              paramStr: "orgId:"+newValue,
            };

             var result = await OrderService.executeSql(params);
             
             this.formData["23868-142002621"].value = result.meta.resList.executeSqlResps[0].org_name;


             var params = {
              interFaceType: "ORDER",
              sqlId:"2021072802",
              paramStr: "orgId:"+oldValue,
            };

             var result = await OrderService.executeSql(params);
             
            this.formData["23868-100013695"].value = result.meta.resList.executeSqlResps[0].org_name;

      }
     },
    }
};
</script>

